<!-- 右侧拉出 - 选择结构 -->
<div class="modal fade struct-select" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-right modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title h4">数据结构字典</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true"><i class="fal fa-times"></i></span>
                </button>
            </div>
            <div class="modal-body">

                <div class="form-row">
                    <div class="col-md-6 mb-3">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span class="input-group-text">所属项目</span>
                            </div>
                            <select class="form-control struct-select-project"
                                uuim-api="developer.project.module.listAll,module_list,module_id,module_code_path"
                                uuim-api-data='{"project_id":uim.app.work_project.project_id}'
                                uuim-value="{#data.module_id || ''#}">
                                <option value="{#uim.app.work_project.project_id#}">
                                    {#uim.app.work_project.project_name#}</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6 mb-3">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span class="input-group-text">所属模块</span>
                            </div>
                            <select class="form-control struct-select-module">
                                <option value="">不限</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6 mb-3 struct-select-type-group">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span class="input-group-text">数据类型</span>
                            </div>
                            <select class="form-control struct-select-type" uim-enum="developerDataStructType">
                                <option value="">不限</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-4 mb-3 d-none">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span class="input-group-text">结构体</span>
                            </div>
                            <select class="form-control struct-has-child" uim-enum="developerDataStructIncludeChild">
                                <option value="">不限</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6 mb-3 struct-nochild">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span class="input-group-text">关键字</span>
                            </div>
                            <input type="text" class="form-control struct-select-keywords">
                        </div>
                    </div>
                </div>

                <div class="frame-wrap">
                    <table class="table table-bordered table-hover m-0 struct-select-list">
                        <thead class="thead-themed">
                            <tr>
                                <th>结构名称</th>
                                <th>结构代码</th>
                                <th>结构类型</th>
                                <th>示例值/子结构</th>
                                <th>备注</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
                <div id="page-info"></div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-warning referer-select-struct-list">刷新列表</button>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="tpl-struct-select-list">
    {#ignore #}
    {#if project_list.length#}
    {#for arr="project_list" key="vo"#}
    <tr data-id="{#vo.struct_id#}">
        <td>{#vo.struct_name#}</td>
        <td>
            {#if vo.struct_must == uim.enum.commomBoolean.TRUE#}
            <span class="badge badge-primary">必传</span>
            {#else#}
            <span class="badge badge-warning">可选</span>
            {#/if#}
            {#vo.struct_code#}
        </td>
        <td>{#uim.enum.developerDataStructType[vo.struct_type]#}</td>
        <td>{#vo.struct_sample#}{#if vo.child_struct_ids#}<span class="badge badge-info">有子结构</span>{#/if#}</td>
        <td>{#vo.struct_desc#}</td>
        <td><span class="btn btn-outline-info btn-xs struct-select-btn px-1 add">添加</span>
            <span class="btn btn-outline-info btn-xs struct-select-btn px-1 copy">复制</span></td>
    </tr>
    <!-- render.bug:此处要多空一行 -->

    {#/for#}
    {#else#}
    <tr>
        <td colspan="6">无搜索结果！</td>
    </tr>
    {#/if#}
    {#/ignore#}

</script>
<script>
    var show_modal = function (target, view, data) {
        var this_modal;
        return this_modal;
    }
    uim.api.emit({
        code: 'project.list',
        data: {
            project_id: $('.modal.struct-select .struct-select-project').val(),
            module_id: $('.modal.struct-select .struct-select-module').val(),
            struct_type: $('.modal.struct-select .struct-select-type').val(),
            has_child: $('.modal.struct-select .struct-has-child').val(),
            keywords: $('.modal.struct-select .struct-select-keywords').val(),
        },
        success: function (data) {
            loading_dialog.hide();
            data_struct_dictionary_list = uim.array_column_kv(data.data_struct_dictionary_list, 'struct_id');
            uim.render({
                data,
                template: 'tpl-struct-select-list',
                template_type: 1, // 0默认为模板内容字符串（不支持include），1为标签对象（取innerHTML，其中include时从页面dom.getbyId来取），2为在线模板（include从线上获取）；
                cache: false, // 当template_type=2时有效，将会把在线模板缓存到localStorage
                context: window, // 当template_type=1时有效，用于在当前上下文中寻找dom
                done: function (res) {
                    $('table.struct-select-list tbody').html(res.content);

                }
            });
            data.data_struct_dictionary_list.length &&
                uim.render({
                    data: { page_info: data.page_info },
                    template: 'page-info',
                    template_type: 2, // 0默认为模板内容字符串（不支持include），1为标签对象（取innerHTML，其中include时从页面dom.getbyId来取），2为在线模板（include从线上获取）；
                    cache: false, // 当template_type=2时有效，将会把在线模板缓存到localStorage
                    context: window, // 当template_type=1时有效，用于在当前上下文中寻找dom
                    target: 'page-info',
                    done: function (res) { }
                });
        },
        error: function (err) {
            loading_dialog.hide();
            bootbox.alert(err.description);
        }
    })
</script>